/**
 * createUser:曾维录
 * FileName: R
 * Author:   14562
 * Date:     2019/9/17 13:41
 * Description: 全局返回结果实体
 */
package com.javatom.notes.common.model;

import com.javatom.notes.common.enums.HttpReponseCodeEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
@Data
@NoArgsConstructor
public class R<T> implements Serializable {
    private static final long serialVersionUID = -3208774296393709054L;
    private String code;
    private String msg;
    private T data;

    private R(String code, String  msg) {
        this.code = code;
        this.msg = msg;
    }
    private R(String code,String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public static R success(){
        return new R(HttpReponseCodeEnum.SUCCESS.getCode(),HttpReponseCodeEnum.SUCCESS.getDesc());
    }
    public static<T> R<T> success(T t) {
        return new R(HttpReponseCodeEnum.SUCCESS.getCode(),HttpReponseCodeEnum.SUCCESS.getDesc(),t);
    }
    public static R fail(HttpReponseCodeEnum httpReponseMsgEnum) {
        return new R(httpReponseMsgEnum.getCode(),httpReponseMsgEnum.getDesc());
    }
    public static R fail(HttpReponseCodeEnum httpReponseMsgEnum,String msg) {
        return new R(httpReponseMsgEnum.getCode(),msg);
    }
    public static R fail(String code,String msg) {
        return new R(code,msg);
    }

}
